package leetcode_1801_1900;

import java.util.Arrays;

public class LeeCode_1829 {
    public static void main(String[] args) {
        System.out.println(Arrays.toString(getMaximumXor(new int[]{0, 1, 1, 3}, 2)));
    }
    private static int[] getMaximumXor(int[] nums, int maximumBit) {
        int n = nums.length;
        int[] p = new int[n];
        p[0] = nums[0];
        for (int i = 1; i < n; i++) {
            p[i] = p[i - 1] ^ nums[i];
        }
        int[] ans = new int[n];
        for (int i = 0; i < n; i++) {
            int pre = p[n - 1 - i];
            int tmp = 0;
            for (int j = 0; j < maximumBit; j++) {
                if ((pre & (1 << j)) == 0){
                    tmp |= 1 << j;
                }
            }
            ans[i] = tmp;
        }
        return ans;
    }
}
